package com.hawthorn.admin.controller.sysmessage;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.service.sysmessage.SysMessageService;
import com.hawthorn.platform.context.ContextHolder;
import com.hawthorn.platform.exception.BizCode;
import com.hawthorn.platform.utils.common.MyUtil;
import com.hawthorn.platform.utils.iassert.AssertMyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>todo 消息管理</p>
 * @author: andyten@tom.com | xukaixing@hotmail.com
 * @created: 2021/11/25 4:19 PM
 * @version v1.0.2
 * @copyright: Copyright (c)  andyten
 */
@Api(tags = {"admin-sysmessage"})
@RestController
@RequestMapping("/sysmessage/")
@Slf4j
public class SysMessageController
{

  @Autowired
  private SysMessageService sysMessageService;

  @ApiOperation(value = "查询->查询1周内所有的待办提醒数", notes = "查询1周内所有的待办提醒数")
  @ApiImplicitParams({
  })
  @GetMapping(value = "/findMsgOneWeekNums")
  public Integer findMsgOneWeekNums()
  {
    String userAccount = ContextHolder.getUserAccount();
    AssertMyUtil.notNull(userAccount, BizCode.VARIABLE_NOT_EMPTY, "userAccount");
    return sysMessageService.findMsgOneWeekNums(userAccount);
  }

  @ApiOperation(value = "查询->查询1周内所有的待办", notes = "查询1周内所有的待办")
  @ApiImplicitParams({
  })
  @GetMapping(value = "/findMsgOneWeek")
  public List<Map<String, Object>> findMsgOneWeek()
  {
    String userAccount = ContextHolder.getUserAccount();
    AssertMyUtil.notNull(userAccount, BizCode.VARIABLE_NOT_EMPTY, "userAccount");
    return sysMessageService.findMsgOneWeek(userAccount);
  }

  @ApiOperation(value = "查询->查询1周内所有的消息", notes = "查询1周内所有的消息")
  @ApiImplicitParams({
  })
  @GetMapping(value = "/findMsgOneWeek2")
  public List<Map<String, Object>> findMsgOneWeek2()
  {
    String userAccount = ContextHolder.getUserAccount();
    AssertMyUtil.notNull(userAccount, BizCode.VARIABLE_NOT_EMPTY, "userAccount");
    return sysMessageService.findMsgOneWeek2(userAccount);
  }

  @ApiOperation(value = "查询->查询全部消息", notes = "查询全部消息")
  @ApiImplicitParams({
  })
  @PostMapping(value = "/findAllMsg")
  public IPage<Map<String, Object>> findAllMsg(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return sysMessageService.findAllMsg(page, conditions);
  }

  @ApiOperation(value = "查询->查询强制阅读的待办提醒", notes = "查询强制阅读的待办提醒")
  @ApiImplicitParams({
  })
  @GetMapping(value = "/findMsgForeceView")
  public List<Map<String, Object>> findMsgForceView()
  {
    String userAccount = ContextHolder.getUserAccount();
    AssertMyUtil.notNull(userAccount, BizCode.VARIABLE_NOT_EMPTY, "userAccount");
    return sysMessageService.findMsgForceView(userAccount);
  }

  /**
   * <p>todo 更新消息状态为已完成</p>
   * @author: andy.ten@tom.com
   * @date: 2021/12/17 12:11 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "更新->更新消息状态为已完成", notes = "更新消息状态为已完成")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "msgId", value = "消息id", dataTypeClass = Long.class)
  })
  @PutMapping(value = "/updateMsgForFinish/{msgId}")
  public void updateMsgForFinish(@PathVariable("msgId") Long msgId)
  {
    String userAccount = ContextHolder.getUserAccount();
    AssertMyUtil.notNull(msgId, BizCode.METHOD_ARGS_NOTNULL, "msgId");
    sysMessageService.updateMsgForFinish(msgId, userAccount);
  }
}
